import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/9 21:17
 */

public class Demo7 {
    public static Object locker = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("t1等待之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t1等待之后");
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2等待之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t2等待之后");
        });

        Thread t3 = new Thread(() -> {
            System.out.println("t3等待之前");
            synchronized (locker) {
                try {
                    locker.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t3等待之后");
        });

        Thread t4 = new Thread(() -> {
            Scanner in = new Scanner(System.in);
            System.out.println("输入任意内容，唤醒一个线程：");
            in.next();
            synchronized (locker) {
                locker.notify();
            }
        });

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}